<?  include('../includes/loader.inc.php'); 

	$config = array (
		'title' 	=> 'Reporte',
		'module' 	=> 'reporte',
		'class'		=> 'eventos',
	);

	if (!$Usuario->logged()) {
		header("Location: /admin/");
		exit;
	}

	// Instancio eventos
	$Eventos = new Eventos();

	// Defino el tipo de evento
	$Eventos->tipo($id_tipo_evento);
	
	$tipo_evento = $Eventos->tipos($id_tipo_evento);

	// Obtengo el reporte de asistentes
	$reporte = $Eventos->reporte_asistentes($id_tipo_evento);

/*
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

        series: [{
            name: 'Asistentes',
            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }, {
            name: 'Confirmadas',
            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }]
*/

	// Esto es solo un ejemplo, asi que solo dejo los ultimos 10 eventos
	$reporte = array_slice($reporte, -10, 10);

	// Preparo las categorias para el graph
	$asistentes = array('name' => 'Asistentes', 'data' => array());
	$confirmadas = array('name' => 'Confirmadas', 'data' => array());
	foreach ($reporte as $rep) {
		$categories[] = '\''.$rep['evento'].' ('.strftime("%b %Y", strtotime($rep['fecha'])).')\'';
		$asistentes['data'][] = (int)$rep['asistentes'];
		$confirmadas['data'][] = (int)$rep['confirmados'];
	}

	$graph['categories'] = '['.implode(',', $categories).']';
	$graph['series'] = '['.json_encode($asistentes).','."\n".json_encode($confirmadas).']';

//echo '<pre>'.print_r($reporte, true).'</pre>';
//echo '<pre>'.print_r($graph, true).'</pre>';

?>
<!DOCTYPE html>

<html>

<head>
	
	<title><?=$config['title']?></title>
	
	<?	include('modules/head.inc.php'); ?>

</head>

<body class="<?=$admin['config']['theme']?>">

	<!--<div class="login-back"></div>

	<div class="titlebar"></div>
	
	<div class="window">
	
		<div class="content">-->

			<?  include('modules/header.inc.php'); ?>
							
			<div class="space clear"></div>

			<div class="container" data-object="">
			
				<h2><?=($config['title'])?></h2>
				
				<div class="space clear"></div>
			
				<!-- Content -->

				<form method="post" action="<?=$PHP_SELF?>" class="browse" id="select-list">

				<div class="left" id="graph" style="width: 100%; margin-bottom: 30px; height: 400px;">

						<div class="legend"><h3>Reporte de asistentes</h3></div>				
						
						<? if ($data['listado']): ?>
					
						<ul id="item-list" class="list">
								
							<li class="th">
							
								<!-- Select All -->
								<p>
									<input data-action="selectall" type="checkbox">
								</p>
							
								<!-- Name of columns -->
								<? foreach ($data['titles'] as $k): ?>
									
									<? if ($k != $data['key']): ?>
									
										<p><?=$k?></p>
									
									<? endif; ?>
									
								<? endforeach; ?>
							
								<!-- Search -->
								<p>Acciones</p>
							
							</li>
							
							<!-- Rows -->
							
							<? foreach($data['listado'] as $key_item => $value_item):  ?>

								<li class="td">
								
									<!-- Checkboxes -->
									<p>							
										<input type="checkbox" name="data[id][<?=$key_item?>]" value="<?=$key_item?>">
									</p>
								
								
									<!-- Data -->
									<? foreach ($data['titles'] as $k => $v): ?>
										
										<p><?=($value_item[$k])?>&nbsp;</p>
									
									<? endforeach;?>
								
									<!-- Direct Actions -->
									<p>
										<span class="invisible actions">
											<? foreach($data['actions'] as $key_action => $value_action): ?>
												<a href="/admin/<?=$value_action['link']?>/key:<?=$key_item?>"><span class="icon ui-icon-triangle-1-e"></span><?=$value_action['name']?></a>
											<? endforeach; ?>
												<a href="/admin/<?=$config['module']?>/modificar/<?=$key_item?>"><span class="icon ui-icon-wrench"></span>Modificar</a>
												<!-- <a onClick="return confirm('Estas seguro que queres borrar el registro?');" href="/admin/<?=$config['module']?>/eliminar/<?=$key_item?>"><span class="icon ui-icon-trash"></span>Borrar</a> -->
										</span>
									</p>
								
								</li>

							<? endforeach; ?>
						
						</ul>
						
						<div class="submits">
				<!--
							<div class="buttonset">
								<button name="data[action]" value="update">Update</button>
								<button name="data[action]" value="delete">Remove</button>
							</div>
				-->
							<div class="paginator">
								<?	if ($data['pagina'] > 1): ?>
									<span><a href="<?=$URI.'/pagina:'.($data['pagina']-1)?>/">Anterior</a></span>
								<?	endif; ?>
								<?	for ($i = 1; $i <= (int)$data['paginas']; $i++): ?>
									<span><a href="<?=$URI.'/pagina:'.$i?>/" <?=($i == $data['pagina'])? 'class="current"' : ''?>><?=$i?></a></span>
								<?	endfor; ?>
								<?	if ($data['pagina'] < $data['paginas']): ?>
									<span><a href="<?=$URI.'/pagina:'.($data['pagina']+1)?>/">Siguiente</a></span>
								<?	endif; ?>
							</div>
						</div>

					<? else: ?>

						<div class="submits">No hay registros para mostrar.</div>

					<? endif; ?>

				</div>

				</form>

				<!-- / Table of items -->

				<!-- /Content -->

				
			</div>

			<?	include('modules/footer.inc.php'); ?>
		
		<!--</div>
		
	</div>-->
			
<script src="/admin/js/universal.js"></script>

<!-- Grafico -->
<script src="/admin/js/highcharts.js"></script>

<script>

var chart;
$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'graph',
            type: 'line',
            marginRight: 130,
            marginBottom: 45
        },
        title: {
            text: 'Reporte de asistentes reales vs confirmados ',
            x: -20 //center
        },
        subtitle: {
            text: 'Tipo de evento: <?=$tipo_evento['tipo']?>',
            x: -20
        },
        xAxis: {
            categories: <?=$graph['categories']?>
        },
        yAxis: {
            title: {
                text: 'Cantidad'
            },
            plotLines: [{
                value: 0,
                width: 100,
                color: '#808080'
            }]
        },
/*
        tooltip: {
            formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                    this.x +': '+ this.y +'°C';
            }
        },
*/
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
		series: <?=$graph['series']?>
    });
});

</script>

</body>	
	
</html>
